using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;

namespace ScreenSnapper
{
    public partial class DirInputDlg : Form
    {
        private bool bWantsSave = false;
        private string _defaultDirectory;

        public DirInputDlg()
        {
            InitializeComponent();
            SetDefaultDirectory();
        }

        public void SetDefaultDirectory()
        {
            _defaultDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
            Object o = Registry.GetValue("HKEY_CURRENT_USER\\Software\\Lexware\\ScreenSnapper", "OutputDirectory", null);
            if (null != o)
                _defaultDirectory = (string)o;
            lbDirectory.Text = _defaultDirectory;
        }

        public string GetFileName()
        {
            string strPath = lbDirectory.Text;
            strPath += "\\";
            string strFileName = edFilename.Text;
            if (!strFileName.EndsWith(".png", true, null))
                strFileName += ".png";
            strPath += strFileName;

            return strPath;
        }

        public string GetPath()
        {
            return lbDirectory.Text;
        }

        public bool WasSaveClicked()
        {
            return bWantsSave;
        }

        private void btSave_Click(object sender, EventArgs e)
        {
            bWantsSave = true;
            Close();
        }

        private void btCancel_Click(object sender, EventArgs e)
        {
            bWantsSave = false;
            Close();
        }

        private void _btChangeOutputDir_Click(object sender, EventArgs e)
        {
            _folderBrowserDialog.SelectedPath = _defaultDirectory;
            if (DialogResult.OK == _folderBrowserDialog.ShowDialog(this))
            {
                _defaultDirectory = _folderBrowserDialog.SelectedPath;
                lbDirectory.Text = _defaultDirectory;
                Registry.SetValue("HKEY_CURRENT_USER\\Software\\Lexware\\ScreenSnapper", "OutputDirectory", _defaultDirectory);
            }
        }
    }
}